<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class AdminBackup extends Command
{
    protected $signature = 'admin:backup';

    protected $description = '备份后台相关数据, 菜单、权限等';

    protected $tables = [
        'menus',
        'roles',
        // 'role_users',
        'role_access',
        'role_permissions',
    ];

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $bar = $this->output->createProgressBar(count($this->tables));
        $bar->start();

        foreach ($this->tables as $table) {
            $this->callSilent('iseed', [
                'tables' => $table,
                '--force' => true,
                '--dumpauto' => false,
            ]);

            $bar->advance();
            sleep(1);
        }

        $bar->finish();

        $this->line("\n");
        $this->info('backup success');
    }
}
